home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Collections: MegaDisc
/
MegaDisc 41 (1994-09)(MegaDisc Digital Publishing)(AU)(Disk 2 of 2).zip
/
MegaDisc 41 (1994-09)(MegaDisc Digital Publishing)(AU)(Disk 2 of 2).adf
/
ARexx_&_HBook
/
HyperText
/
Builder
next >
Wrap
Text File
|
1994-07-30
|
11KB
|
269 lines
/* */
/* Builder - A driver for a HyperBook implementation
of hypertext methods for text perusal
By John Collett Hamilton, NZ July, 1994 */
signal on syntax ; signal on error /* Error trap */
/* Placed here for convenience
If for some reason you want to process fewer pages than the whole file
- you might be at an exploratory or developmental stage - set templimit
to a non-zero value to process just that number of pages. */
templimit = 0
/* Master1 AND (HyperBook OR HBReader) must be present. */
a.1 = 'Master1' ; a.2 = 'HyperBook'; a.3 = 'HBReader'
if ~exists(a.1) then do ; say a.1 ' not found.' ; exit ; end
hpb = (exists(a.2)) ; hbr = (exists(a.3))
if ~(hpb | hbr) then do
say 'Neither 'a.2' nor 'a.3' found.' ; exit ; end
address command 'copy Master1 Master2'
/* Launch HBReader, if present; if not, launch HyperBook.
HyperBook (or HBReader) is being run from this external program.
So calls to all HyperBook functions need to be prefixed by 'HML_'. */
if hbr then address command 'HBReader Master2'
else do ; address command 'HyperBook Master2'
call HML_TinyPanel() ; end
/* Colour settings here. Change them if you want to. */
c.0 = '69D' ; c.1 = '000' ; c.2 = 'FFF' ; c.3 = 'CEF'
c.4 = 'FA4' ; c.5 = 'E00' ; c.6 = '03F' ; c.7 = '0BF'
do i = 0 to 7 ; o = HML_SetPageRGB(':',i,X2D(c.i)) ; end
nleft = 8 ; ntop = 10 ; cr = '0a'x ; IsLabel = 0 ; main = 1
/* file = 'ltdocs' */ /* Line A */
file = HML_FileRequest("Select your source file",'') /* Line B */
/* If you are working regularly on a given text (exploratory or
developmental work), then use line A of the above pair, quoting the
name of whatever file you are working on. Otherwise use line B.
Simply comment out the one you are not using. */
if open(fr, file, 'r') = 0 then exit
/* Create a 'note' template to hold the patches of text. */
nm = HML_CreateNote() ; call HML_SetBorder(nm,-1)
o = HML_ShadowStyle(nm,2) ; call HML_SetShadow(nm,-1)
/* Master2 starts life as a copy of Master1, a single page
containing templates of notes, buttons, and drawings for later use.
Further pages will be added to it, the final collection being
stored in the destination file. The name of that file will be :
your file name, plus the extension '.ht'. Here we copy required
templates to the bin, and delete them from Master2.
'Clone' followed by 'Delete' is less elegant that 'ReLocate', but
appears to produce a more complete copy (inc. colour settings etc). */
small = HML_Clone('Small'(),'0:') ; call HML_Delete('Small'())
large = HML_Clone('Large'(),'0:') ; call HML_Delete('Large'())
d1 = HML_Clone('Drawing1'(),'0:') /* For coloured backgrounds */
d2 = HML_Clone('Drawing2'(),'0:') /* For transparent overlay */
call HML_Delete('Drawing1'()) ; call HML_Delete('Drawing2'())
call HML_Delete('Blurb1'()) ; call HML_Delete('Blurb2'())
/* Why TWO 'drawings' to mark highlighted words? The coloured bar
has to be BEHIND the chunk it hilights, so as not to hide it. The
other drawing, transparent, is IN FRONT OF the chunk, which is where
it has to be if it is to act as an active gadget. */
d3 = HML_Clone('Head'(),'0:') /* Box for page headline */
d4 = HML_Clone('Header'(),'0:') /* Text for page headline */
call HML_Delete('Head'()) ; call HML_Delete('Header'())
/* The clumsy doubling-up of 'Head' and 'Header' (when one little note
should have been enough) is to cater for the inability of HBReader to
make copies of a note, for highlighted chunks, which are smaller in
either direction than the default size (61 x 23). All very annoying!
*/
d5 = HML_Clone('Hook'(),'0:') /* End-of-section marker */
call HML_Delete('Hook'())
/* Main processing loop, page by page, starts here */
title = substr(file,index(file,':') + 1)
pageno = 1 ; labelno = 1 ; box. = ''
do until eof(fr)
/* Read in text until text break is found or tally > 30 */
tally = 1 ; txt = '' ; nbox = 0
do forever
tally = tally + 1 ; line = readln(fr)
if eof(fr) | strip(line) = '.' then leave
if substr(strip(line),1,3) = '.Bx' then do
nbox = nbox + 1 ; tally = tally - 1 ; box.nbox = line ; iterate ; end
txt = txt || line || '0a'x ; if tally > 30 then leave
end
linecount = tally - 1 + eof(fr)
call MakeNote() /* Put the text on the page */
call BuildGads() /* Hilight marked text */
if nbox > 0 then call DrawBox()
/* Jump to end of file if templimit has been reached */
if (templimit) > 0 & (pageno = templimit) then se = seek(fr,0,'e')
if ~eof(fr) then do /* Create the next page */
pageno = pageno + 1 ; page = HML_CreatePage(':',pageno)
labelno = labelno + 1
old = HML_GoToPage(page)
end
end /* of page-by-page loop */
call PNumbers() /* A reverse sweep through pages to show nos etc. */
/* Store file with new name. Close down. Tidy up. */
call close(fr)
fileht = file || '.ht' ; b = HML_SaveHyperBook(fileht)
cmd = 'copy Master1.info ' || fileht || '.info'
address command cmd
address command 'Delete Master2 >NIL:'
a = " Processing done." cr "Output saved as " || fileht cr
b = "Want to run it now?" cr
c = HML_GetResponse(a b)
if c then call HML_LoadHyperBook(fileht)
else call HML_QuitHyperBook()
Finish: exit
/* End of program : Functions follow */
syntax: say 'Syntax : 'rc errortext(rc) '. Line 'sigl ; signal 'Finish'
error: say 'Error : 'rc sigl ; signal 'Finish'
MakeNote:
/* Is the first character a '.'?
If so: This is a 'note'.
Remove its first line.
Use the label as the name of the new page. */
firstchar = substr(strip(txt,'l'),1,1)
IsLabel = (firstchar = '.')
if IsLabel then do
main = 0
dotpos = index(txt,'.',1) ; endpos = index(txt,'0a'x,1)
label = substr(txt,dotpos+1,endpos-1)
label = strip(compress(label,'.'||'0a'x))
labelno = 1 ; title = label
txt = substr(txt,endpos + 1,length(txt))
newname = title || ' 1'
end
else if main then newname = title || ' ' || pageno
else newname = title || ' ' || labelno
ctxt = compress(txt,'`') /* Remove the ` markers */
p = HML_CurrentPage() ; note = HML_Clone(nm,'0:')
o = HML_SetName(HML_CurrentPage(),newname)
call HML_ScaleToSize(note,620,linecount * 8 + 8)
call HML_SetPosition(note,nleft,ntop)
call HML_InsertText(note,ctxt,0) ; note = HML_ReLocate(note, p)
h = HML_Clone(d3,'0:') /* Box for page title */
call HML_ScaleToSize(h,length(newname)*8 + 24,10)
call HML_SetActionMacro(h,'FrameSpec') ; h = HML_Relocate(h,':')
h2 = HML_Clone(d4,'0:') /* Text of page title */
call HML_ScaleToSize(h2,length(newname)*8 + 24,10)
o = HML_ReplaceText(h2,newname,0,-1)
call HML_SetActionMacro(h2,'FrameSpec'); h = HML_Relocate(h2,':')
return
BuildGads:
/* Any words or phrases in the source text enclosed `thus` will be
hi-lighted. In standard hypertext fashion, when clicked on, they
take you to the page containing related text. */
/* Cut the note text into lines */
call HML_InterActive(1)
chunk. = '' ; pos = -1 ; start = 1 ; linecount = 0 ; markcount = 0
do until pos = 0
pos = index(txt,'0a'x,start) ; if pos = 0 then leave
linecount = linecount + 1 ; thisline = substr(txt,start,pos-start+1)
if length(thisline) > 2 then
/* Find any marked words in the line */
mark1 = -1 ; aa = 1 ; adj = 0
do until mark1 = 0
mark1 = index(thisline,"`",aa) ; if mark1 = 0 then leave
/* Find partner, or next space, or end of line. */
mark2 = index(thisline,"`",mark1+1)
if mark2 = 0 then do
mark2 = index(thisline," ",mark1+1)
if mark2 = 0 then mark2 = length(thisline)
end
markcount = markcount + 1
adj = adj + 1 /* To adjust text when markers removed */
chunk.markcount = substr(thisline,mark1+1,mark2-mark1-1)
charleft = nleft + mark1*8 + 14 - adj*16
chardown = ntop + 1 + linecount*8
call MakeGadget() /* Build a gadget for that chunk of text */
aa = mark2 + 1
end /* of that line treatment */
start = pos + 1
end /* of dealing with markers on that page */
return
MakeGadget:
call HML_InterActive(0) /* For less flickering */
len = length(chunk.markcount) * 8
Dr1= HML_Clone(d1,'0:') /* Coloured bar, behind */
call HML_ScaleToSize(Dr1,len+4,8)
call HML_SetPosition(Dr1,charleft+1,chardown-8)
o = HML_SetName(Dr1,chunk.markcount || '2')
gad= HML_Relocate(Dr1,':') ; gad = HML_ObjectToBack(gad)
Dr2= HML_Clone(d2,'0:') /* Transparent, in front, active */
call HML_ScaleToSize(Dr2,len+10,8)
call HML_SetPosition(Dr2,charleft-2,chardown-8)
act= HML_SetActionMacro(Dr2,'Link')
o = HML_SetName(Dr2,chunk.markcount) ; gad = HML_Relocate(Dr2,':')
return
/* Back through all pages to add cosmetic touches */
PNumbers:
num = HML_NumPages() ; tag = '/' || num
pg1 = HML_SearchName('1:','PageNumber') ; oldstem = ''
do i = num to 1 by -1
op = HML_GoToPage(i || ':') ; cp = HML_CurrentPage()
/* Numbering */
pg = HML_Clone(pg1,cp) ; o = HML_ReplaceText(pg,i || tag,0,-1)
/* Marking last page of each section */
thisname = HML_GetName(cp) ; parse var thisname stem n
if stem ~= oldstem then do
ho = HML_Clone(d5,'0:') ; hook = HML_Relocate(ho,':') ; end
oldstem = stem
end
return
DrawBox: procedure expose small large nbox box.
do j = 1 to nbox
call HML_InterActive(0)
line = box.j ; parse var line cmd l ',' t ',' w ',' h ',' bg .
mini = (w < 62 | h < 24) ; if mini then box= HML_Clone(small,':')
else box= HML_Clone(large,':')
if (mini = 0) & (bg ~= '') then bakg = HML_SetBackGround(box,bg)
b = HML_SetBorder(box,2) ; b = HML_SetShadow(box,1)
call HML_SetPosition(box,strip(l),t)
call HML_ScaleToSize(box,w,strip(h))
f = HML_ObjectToBack(box)
end
return
/* end */